package cn.aiszs.javafx_imp.service;

import cn.aiszs.javafx_imp.mapper.CityMapper;
import cn.aiszs.javafx_imp.pojo.City;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CityService {
    @Autowired
    private CityMapper cityMapper;
    @Autowired
    private City city;
    public City inserphon(String data,String phone){
        JSONObject jsonObject = JSON.parseObject(data);
        JSONObject object = jsonObject.getJSONObject("data");
        city = new City();
        city.setPhone(phone);
        city.setProvince(object.getString("province"));
        city.setCity(object.getString("city"));
        city.setAeracode(object.getString("area_code"));
        city.setPostcode(object.getString("post_code"));
        city.setIsp(object.getString("isp"));
        cityMapper.insert(city);
        return city;
    }
    public Boolean ciExist(String phone){
        QueryWrapper<City> wrapper = new QueryWrapper<>();
        wrapper.eq("phone",phone);
        return cityMapper.selectOne(wrapper)!=null;
    }
    public City selectByPhone(String phone){
        return cityMapper.finCity(phone);
    }
}
